package info.javafans.cdn.dao;

import java.sql.SQLException;

import org.apache.log4j.Logger;

import info.javafans.cdn.database.DbHelper;
import info.javafans.cdn.domain.Member;

/**
 * Project: CollegeDatingNetwork <br />
 * ClassName: MemberDao <br />
 * Description: <br />
 */
public class MemberDao {
	public static Logger logger = Logger.getLogger(MemberDao.class);

	/**
	 * 按id查找Member selectMemberById
	 * 
	 * @param id
	 * @return
	 */
	public static Member selectMemberById(int id) {

		String sql = "select * from member where id = ?";
		Member member = DbHelper.queryBean(Member.class, sql, id);
		return member;
	}
	
	/**
	 * 验证登录
	 * doLogin
	 * @param username
	 * @param password
	 * @return
	 */
	public static Member doLogin(String username, String password) {
		String sql = "select * from member where name = ? and password = ?";
		Member member = DbHelper.queryBean(Member.class, sql, username, password);
		return member;
	}
	
	/**
	 * 注册
	 * doRegister
	 * @param username
	 * @param password
	 * @param phone
	 * @param email
	 * @return
	 */
	public static boolean doRegister(String username, String password, String phone, String email) {
		String sql = "insert into member(name, password, phone, email) values (?,?,?,?)";
		System.out.println("sql:"+sql);
		if (DbHelper.update(sql, username,password,phone,email) == 1) {
			return true;
		}
		else {
			return false;
		}
	}
	
	/**
	 * 判断用户是否已注册
	 * isRegistered
	 * @param username
	 * @return
	 */
	public static boolean isRegistered(String username) {
		String sql = "select * from member where name = ?";
		
		Member m = DbHelper.queryBean(Member.class, sql, username);
		
		return m == null ? false : true;
	}
}
